<%-- 
    Document   : RegisterResult
    Created on : 2019-6-16, 9:17:46
    Author     : 虎
--%>

<%@page import="com.jdbc.domains.User"%>
<%@page import="com.jdbc.daos.UserDao"%>
<%@page import="com.jdbc.dao.impl.UserDaoImpl"%>
<%@page language="java" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<%@page import="java.io.*" %>
<%@page import="javax.servlet.*" %>
<%@page errorPage="error.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>注册结果页面！</title>
        <style>
            #yyy{               
                position: absolute;
                top: 120px;
                left: 400px;
                text-align: center;
            }
        </style>
    </head>
    <body style="background:url(myphoto.png);background-size:cover;">
<%
            String username=request.getParameter("username");
            String passwords1=request.getParameter("password1");
            String passwords2=request.getParameter("password2");
            String name=request.getParameter("name");
            String sex=request.getParameter("sex");
            String ID=request.getParameter("ID");
            String phone=request.getParameter("phone");
            String email=request.getParameter("email");
            String place=request.getParameter("place");
            if(username.equals("")||passwords1.equals("")||passwords2.equals("")||name.equals("")||ID.equals("")||phone.equals("")||email.equals("")){
%>
        <h1 id="yyy">
            注册失败！请检查是否有未填项··· 
        </h1>
<%               
            }else{
                if(!passwords1.equals(passwords2)){
%>
        <h1 id="yyy">
            注册失败！两次输入的密码不相同··· 
        </h1>   
<%               
                }else{
                    UserDao dao = new UserDaoImpl();
                    List<User> allUser= dao.listAll();
                    boolean flag=false;
                    for(User u1 : allUser){
                        if(username.equals(u1.getUserID())){
                            flag=true;break;
                        }
                    }
                    if(flag==true){
 %>
                <h1 id="yyy">
                注册失败！该用户名已被注册··· 
                </h1>
<%
                    }else{
                        User u2 = new User();
                        UserDaoImpl udi=new UserDaoImpl();
                        u2.setUserID(username);
                        u2.setPassword(passwords1);
                        u2.setName(name);
                        u2.setSex(sex);
                        u2.setID(ID);
                        u2.setPhone(phone);
                        u2.setEmail(email);
                        u2.setProvince(place);
                        udi.save(u2);
%>
                    <h1 id="yyy">
                    恭喜<%=name%>注册成功··· 
                    </h1>
<%                      
                    }
                }
            }
%>
    </body>
</html>
